package javabase.enhancestring.split;

import java.util.StringTokenizer;

public class SplitDemo5 {

	   private static final String DELIM = "|";  
	   private static final int SPLITLEN = 10;  
	     
	   private static void useStringTokenizer(String input)     
	   {     
	       StringTokenizer st = new StringTokenizer(input, DELIM, false);     
	        while (st.hasMoreElements()) {   
	            String token = st.nextElement().toString();          
	            System.out.println("StringTokenizer = " + token);        
	        }     
	    }   
	      
	    private static void useSplit(String input)     
	    {     
	        String[] splitStr = input.split("\\|", SPLITLEN);  
	        int splitLength = splitStr.length;  
	        for(int i = 0; i < splitLength; i++) {  
	            System.out.println("Split : " + splitStr[i]);  
	         }   
	    }   
	      
	    public static void main(String[] args) {
	    	StringBuilder stringBuilder = new StringBuilder();
	    	for (int i = 0; i < 10; i++) {
				stringBuilder.append(i);
				if (i < 9) {
					stringBuilder.append("|");
				}
			}
	        String input = stringBuilder.toString();     
	        long start1 = System.nanoTime();  
	        useStringTokenizer(input);  
	        System.out.println(System.nanoTime() - start1);  
	        long start2 = System.nanoTime();;  
	        useSplit(input);  
	        System.out.println(System.nanoTime() - start2);  
	    }

}
